package org.BUPT.api.controller;

import lombok.extern.log4j.Log4j2;
import org.BUPT.application.service.CommentService;
import org.BUPT.domain.model.message.AnswerCommented;
import org.BUPT.domain.model.message.CommentCommented;
import org.BUPT.domain.model.question.AnswerBO;
import org.BUPT.domain.model.question.CommentBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Log4j2
@CrossOrigin
public class CommentServiceController {
    @Autowired
    CommentService commentService;
    /**
     * POST
     * 用户评论一个回答或另一条评论
     * @param userId: 评论者id
     * @param answerId: 所评论所属于的回答id
     * @param parentId: 所评论的对象id（若评论的是一条回答，则该值为-1）
     * @param content: 所评论的内容
     * @return 若评论发表成功，则回复空字符串，若失败，则返回失败信息
     */
    @PostMapping("/addComment")
    public void addComment(
            @RequestParam(value = "userId") int userId,
            @RequestParam(value = "answerId") int answerId,
            @RequestParam(value = "parentId") int parentId,
            @RequestParam(value = "content") String content
    ){
        try{
            commentService.createComment(userId, answerId, parentId, content);
        }
        catch (Exception e){
            log.info(e.getMessage());

        }
    }

    /**
     * POST
     * 用户修改一条评论
     * @param commentId: 所修该的评论id
     * @param content: 修改后的评论内容
     * @return 若评论修改成功，则返回空字符串，若失败，则返回失败信息
     */
    @PostMapping("/modifyComment")
    public void modifyComment(
            @RequestParam(value = "commentId") int commentId,
            @RequestParam(value = "content") String content
    ){
        try{
            commentService.modifyComment(commentId,content);

        }
        catch (Exception e){
            log.info(e.getMessage());
        }
    }

}
